package com.ruoyi.boat.controller;

import com.ruoyi.boat.aop.AvoidDuplicate;
import com.ruoyi.boat.domain.AlertHistory;
import com.ruoyi.boat.service.IAlertHistoryService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 告警历史Controller
 *
 * @author ruoyi
 * @date 2023-08-01
 */
@Controller
@RequestMapping("/boat/alertHistory")
public class AlertHistoryController extends BaseController {
    private String prefix = "boat/alertHistory";

    @Autowired
    private IAlertHistoryService alertHistoryService;

    @RequiresPermissions("boat:alertHistory:view")
    @GetMapping()
    public String alertHistory() {
        return prefix + "/alertHistory";
    }

    /**
     * 查询告警历史列表
     */
    @RequiresPermissions("boat:alertHistory:list")
    @PostMapping("/list")
    @ApiOperation("获取BoatDto列表")
    @ResponseBody
    public TableDataInfo list(AlertHistory alertHistory) {
        startPage();
        List<AlertHistory> list = alertHistoryService.selectAlertHistoryList(alertHistory);
        return getDataTable(list);
    }

    /**
     * 导出告警历史列表
     */
    @RequiresPermissions("boat:alertHistory:export")
    @Log(title = "告警历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @AvoidDuplicate
    @ResponseBody
    public AjaxResult export(AlertHistory alertHistory) {
        List<AlertHistory> list = alertHistoryService.selectAlertHistoryList(alertHistory);
        ExcelUtil<AlertHistory> util = new ExcelUtil<AlertHistory>(AlertHistory.class);
        return util.exportExcel(list, "告警历史数据");
    }

    /**
     * 新增告警历史
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存告警历史
     */
    @RequiresPermissions("boat:alertHistory:add")
    @Log(title = "告警历史", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AlertHistory alertHistory) {
        return toAjax(alertHistoryService.insertAlertHistory(alertHistory));
    }

    /**
     * 修改告警历史
     */
    @RequiresPermissions("boat:alertHistory:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        AlertHistory alertHistory = alertHistoryService.selectAlertHistoryById(id);
        mmap.put("alertHistory", alertHistory);
        return prefix + "/edit";
    }

    /**
     * 修改保存告警历史
     */
    @RequiresPermissions("boat:alertHistory:edit")
    @Log(title = "告警历史", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AlertHistory alertHistory) {
        return toAjax(alertHistoryService.updateAlertHistory(alertHistory));
    }

    /**
     * 删除告警历史
     */
    @RequiresPermissions("boat:alertHistory:remove")
    @Log(title = "告警历史", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(alertHistoryService.deleteAlertHistoryByIds(ids));
    }
}
